<?php

class Consolidate_model extends CI_Model {

    function  __construct() {
        parent::__construct();
    }

    function getYeses($tid=NULL) {
        if ($tid) {
            $data['tid'] = $tid;
            $this->db->where($data);
        }
        $query = $this->db->get("yes_no");
        return $query->result();
    }

    function getEIOTypes($tid=NULL) {
        if ($tid) {
            $data['tid'] = $tid;
            $this->db->where($data);
        }
        $query = $this->db->get("set_eio_types");
        return $query->result();
    }

    function getDepartments($tid=NULL) {
        if ($tid) {
            $data['tid'] = $tid;
            $this->db->where($data);
        }
        $query = $this->db->get("set_sbus");
        return $query->result();
    }

    function getServiceTypes($tid=NULL) {
        if ($tid) {
            $data['tid'] = $tid;
            $this->db->where($data);
        }
        $query = $this->db->get("set_service_types");
        return $query->result();
    }

    function getOrgTypes($tid=NULL) {
        if ($tid) {
            $data['tid'] = $tid;
            $this->db->where($data);
        }
        $query = $this->db->get("set_org_types");
        return $query->result();
    }

    function getBusinessTypes($tid=NULL) {
        if ($tid) {
            $data['tid'] = $tid;
            $this->db->where($data);
        }
        $query = $this->db->get("set_bus_types");
        return $query->result();
    }

    function getClients($tid=NULL) {
        if ($tid) {
            $data['tid'] = $tid;
            $this->db->where($data);
        }
        $query = $this->db->get("set_clients");
        return $query->result();
    }

    function getDocTypes($tid=NULL) {
        if ($tid) {
            $data['tid'] = $tid;
            $this->db->where($data);
        }
        $query = $this->db->get("set_document_types");
        return $query->result();
    }

    function getApplicants($username=NULL, $tid=NULL) {
        if ($tid) {
            $data['tid'] = $tid;
            $this->db->where($data);
        }
        if ($username) {
            $data['username'] = $username;
            $this->db->where($data);
        }
        $this->db->select("tid,surname,first_name,other_names,username,dept_id,phone_number,email,idno,pay_roll_no,date_of_employment,date_registered,date_last_login");
        $this->db->from("applicants");
        $query = $this->db->get();
        $result = array();
        foreach ($query->result_array() as $row) {
            unset($row['password']);
            $row['date_registered'] = $this->functions_model->prettyDateTime($row['date_registered']);
            $row['date_last_login'] = $this->functions_model->prettyDateTime($row['date_last_login']);
            $dept = $this->getDepartments($row['dept_id']);
            if (count($dept) > 0) {
                $row['dept_id'] = $dept[0]->name;
            }
            $result[] = $row;
        }
        return $result;
    }

    function getLeaveStatuses($tid=NULL) {
        if ($tid) {
            $data['tid'] = $tid;
            $this->db->where($data);
        }
        $this->db->from("set_leave_status");
        $query = $this->db->get();
        return $query->result();
    }

    function getPercentage($val, $budget) {
        return $val . "&nbsp(" . round(($val * 100 / $budget), 2) . "%)";
    }

}

?>
